//
//  ViewController.m
//  04转场动画
//
//  Created by apple on 15-6-12.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imgView;

@property (nonatomic, assign) int index;
@end

@implementation ViewController




- (IBAction)rightSwipe:(UISwipeGestureRecognizer *)sender {
    
    
    self.index++;
    
    if (self.index > 4) {
        self.index = 0;
    }
    
    NSString *img = [NSString stringWithFormat:@"%d", self.index + 1];
    self.imgView.image= [UIImage imageNamed:img];
    
//    [UIView transitionWithView:self.imgView duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:nil completion:nil];
    
//    // -------------- 转场动画代码 --------------------
//    // 1. 创建一个转场动画对象
    CATransition *trans = [[CATransition alloc] init];
    
    // 设置转场动画的类型
    trans.type = @"cube";
//
//    if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
//        // 向左轻扫
//        trans.subtype = kCATransitionFromRight;
//        
//    } else {
//        // 向右轻扫
//        trans.subtype = kCATransitionFromLeft;
//    }
//    
//    // 把动画添加到图片框上
   [self.imgView.layer addAnimation:trans forKey:nil];
    // -------------- 转场动画代码 --------------------
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
